package feizhou.untils.temp;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import feizhou.untils.tools.StringUtil;
import feizhou.untils.tools.UUIDUtil;
import feizhou.untils.tools.io.IOStreamUtil;
import feizhou.untils.tools.json.JSONUtil;
import feizhou.untils.tools.signature.MD5Signature;
import feizhou.untils.tools.signature.SignatureParam;
import feizhou.untils.tools.signature.SignatureUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


/**
 * @ClassName: DMPUtil
 * @Description 请描述下该类是做什么的
 * @Author feizhou
 * @Date 2023/8/15  15:50
 * @Verson 1.0
 **/
public class DmpUtil {
    private static Map<String, String> map = new HashMap<>();


    //给字段添加注释
    public static void addAnnotation() {
        String filePath = "D:\\java\\workSpace-learn\\java_utils\\java_untils\\src\\main\\java\\fei\\zhou\\java_untils\\tools\\file\\test2.txt";


        List<String> lines = IOStreamUtil.read_bufferedReader(filePath);
        lines.forEach(e -> {
            String[] arr = e.split(",");
            if (arr.length >= 2) {
                map.put(arr[0], arr[1]);
            }

        });

        String f2 = "D:\\java\\workSpace-learn\\java_utils\\java_untils\\src\\main\\java\\fei\\zhou\\java_untils\\tools\\temp\\bean\\";

        File file = new File(f2);
        File[] files = file.listFiles();


        for (File f : files) {
            System.out.println("-------" + f.getName() + "-------");

            for (String line : IOStreamUtil.read_bufferedReader(f.getAbsolutePath())) {
                if (line.contains("private")) {
                    String key = isContains(line);
                    if (key != null) {
                        line = line + "//" + map.get(key);
                    }
                    System.out.println(line);
                }
            }

        }


    }

    public static String isContains(String line) {
        for (String s : map.keySet()) {
            if (line.contains(s)) {
                return s;
            }
        }
        return null;
    }

    public static void buildSetter() {
        String filePath = "D:\\java\\workSpace-learn\\周飞开发的通用工具\\java_util\\src\\main\\java\\feizhou\\untils\\temp\\file\\file.txt";

        List<String> lines = IOStreamUtil.read_bufferedReader(filePath);
        lines.forEach(e -> {
            String[] arr1 = e.split("private String ");
            String str = arr1[1];
            String[] arr2 = str.split(";");
            String name = arr2[0];
            String commnet = arr2[1];
            System.out.println("bean.set" + StringUtil.caseFirstChar(name, 1) + "(null)" + ";" + commnet);


        });


    }

    public static void buildIDs() {
        String filePath = "D:\\java\\workSpace-learn\\java_utils\\java_untils\\src\\main\\java\\fei\\zhou\\java_untils\\tools\\file\\test4.txt";

        List<String> lines = IOStreamUtil.read_bufferedReader(filePath);
        StringBuilder sb = new StringBuilder();
        lines.forEach(e -> {
            sb.append(e + ",");
        });

        String str = sb.deleteCharAt(sb.length() - 1).toString();

        System.out.println(str);
    }

    //字段映射
    public static void fieldMapping() throws JsonProcessingException {
        String json1 = "{   \"businessScopeList\": [],   \"cstomerOrg\": {     \"leafOrgId\": \"37245\",     \"contractType\": \"02,01\"   },   \"customerInfo\": {     \"customerCategory\": \"Z002\",     \"customerName\": \"测试129\",     \"customerAlias\": \"测试123\",     \"belongSys\": \"none\",     \"licenseCreditCode\": \"11112334556456\",     \"licenseEstablishDate\": \"2023-10-09\",     \"licenseAddress\": \"营业执照信息详细地址\",     \"licensePersonName\": \"法人姓名\",     \"licensePersonId\": \"11112334556456\",     \"businessLicenseNo\": \"11112334556456233\",     \"businessLicensePeriod\": \"2023-10-20\",     \"accountName\": \"账户名称\",     \"accountNumber\": \"账户号码\",     \"accountPersonName\": \"法定代表人\",     \"accountBankName\": \"开户行名称\",     \"officeAddress\": \"办公场所信息详细地址\",     \"officeArea\": \"办公面积\",     \"licenseProvinceId\": \"110000\",     \"licenseCityId\": \"110100\",     \"licenseDistrictId\": \"110101\",     \"officeProvinceId\": \"120000\",     \"officeCityId\": \"120100\",     \"officeDistrictId\": \"120101\",     \"loadConditions\": \"10\",     \"deliverFrequency\": \"11\",     \"unloadRequirement\": \"01\",     \"firstDeliverDate\": \"2023-09-29\",     \"deliverNotes\": \"备  注\",     \"invoiceAttribute\": \"1\",     \"invoiceProperty\": \"1\",     \"invoiceHeader\": \"发票抬头\",     \"invoiceIdNumber\": \"1212424234\",     \"invoiceAddress\": \"开票地址\",     \"invoiceTelephone\": \"开票电话\",     \"invoiceBankName\": \"开户行名称\",     \"invoiceBankAccount\": \"银行账号\",     \"invoiceBankUserName\": \"银行账户名\",     \"accountBankNumber\": \"联 行 号\",     \"invoiceType\": \"wxkp\",     \"invoiceMailAddress\": \"邮寄地址\",     \"priceGroupId\": \"E4\",     \"taxClass\": \"0\",     \"acceptType\": \"1\",     \"paymentCondition\": \"Z004\",     \"sumSubject\": \"1231030000\",     \"currency\": \"CNY\",     \"customerPriceClass\": \"R\",     \"customerSubjectGroup\": \"20\",     \"payType\": \"01\"   },   \"customerPartnerList\": [],   \"receiveInfo\": {     \"address\": \"收货、配送信息详细地址\",     \"contacts\": \"收货联系人\",     \"contactNumber\": \"123456788923\",     \"specialRequirements\": \"备  注\",     \"receiveTimeBegin\": \"2023-10-12\",     \"receiveTimeEnd\": \"2023-10-28\"   } }";
        String json2 = "{   \"efc_date\": 1695954107742,   \"billing_address\": \"开票地址\",   \"customer_price_group\": \"E4\",   \"CREATOR_ID\": 145507,   \"delivery_cycle\": \"11\",   \"CREATE_DEPT_CODE\": \"D006413\",   \"FLOW_STEP_NAME\": \"环节1\",   \"id\": \"1711206207282221057\",   \"currentNumber\": null,   \"bank_name0\": \"开户行名称\",   \"bank_statement_atta\": \"{\\\"value\\\":\\\"344937562091503616\\\"}\",   \"venue_photos_atta\": \"{\\\"value\\\":\\\"344937561806290944\\\"}\",   \"receiving_person\": \"收货联系人\",   \"practitioner\": \"111\",   \"create_dept\": \"[{\\\"type\\\":\\\"Group\\\",\\\"code\\\":\\\"37245\\\",\\\"name\\\":\\\"常温龙岗办\\\",\\\"attrs\\\":null}]\",   \"check_accept_type\": \"1\",   \"car_atta\": \"{\\\"value\\\":\\\"344937561827262464\\\"}\",   \"custom_nature\": \"1\",   \"new_reason\": \"新增（设立）原因\",   \"legal_person_idcard\": \"11112334556456\",   \"idcard_atta\": \"{\\\"value\\\":\\\"344937561764347904\\\"}\",   \"province_city_district3\": \"天津市,市辖区,和平区\",   \"corporate_seal_atta\": \"{\\\"value\\\":\\\"344937562066337792\\\"}\",   \"contract_type\": \"02,01\",   \"pricing_customer_type\": \"R\",   \"tax_type\": \"0\",   \"remarks2\": \"备  注\",   \"belongedOrgId\": 25443,   \"bank_account_atta\": \"{\\\"value\\\":\\\"344937562041171968\\\"}\",   \"food_business_period_validity01\": 1696558907737,   \"custom_type\": \"Z002\",   \"food_business_period_validity02\": 1697768507738,   \"MODIFY_EMP_ID\": 145507,   \"distribution_brand\": \"cwcp\",   \"food_business_atta\": \"{\\\"value\\\":\\\"344937561785319424\\\"}\",   \"Invoice_header\": \"发票抬头\",   \"billing_type\": \"wxkp\",   \"currency\": \"CNY\",   \"custome_account_group\": \"20\",   \"target_task_03\": null,   \"target_task_02\": \"低温目标任务\",   \"target_task_01\": \"常温目标任务\",   \"creator_people\": \"[{\\\"type\\\":\\\"User\\\",\\\"code\\\":\\\"raolanfeng\\\",\\\"name\\\":\\\"饶兰凤\\\",\\\"attrs\\\":null}]\",   \"legal_representative\": \"法定代表人\",   \"CREATOR_ACCOUNT\": \"raolanfeng\",   \"bank_account_num\": \"账户号码\",   \"businessTypeId\": 204616,   \"instId\": 31688,   \"bank_account_name\": \"账户名称\",   \"warehouse_atta\": \"{\\\"value\\\":\\\"344937561848233984\\\"}\",   \"normalTCD\": 1111,   \"delivery_capacity\": \"大卡车\",   \"receiving_data2\": 1698459707746,   \"receiving_data1\": 1697077307745,   \"MODIFY_EMP_ACCOUNT\": \"raolanfeng\",   \"reconciliation_account\": \"1231030000\",   \"lowTCD\": 1222,   \"shipping_conditions\": \"10\",   \"authorized_distribution_area\": \"授权经销区域\",   \"detail_address2\": \"办公场所信息详细地址\",   \"detail_address3\": \"收货、配送信息详细地址\",   \"CREATION_TIME\": 1696818327107,   \"bank_account_name0\": \"银行账户名\",   \"business_license\": \"{\\\"value\\\":\\\"344937561739182080\\\"}\",   \"sb_merchants_count\": 111,   \"custom_name\": \"测试123\",   \"CREATE_DEPT_ID\": 37245,   \"businessTypeName\": \"客户开户申请\",   \"network_detail\": \"{\\\"value\\\":\\\"344937561240059904\\\"}\",   \"credit_code\": \"11112334556456\",   \"MODIFY_EMP_NAME\": \"饶兰凤\",   \"taxpayer_IdCard\": \"1212424234\",   \"affi_orgz_01\": \"[{\\\"type\\\":\\\"Group\\\",\\\"code\\\":\\\"25882\\\",\\\"name\\\":\\\"公司领导\\\",\\\"attrs\\\":null}]\",   \"create_time\": null,   \"detail_address\": \"营业执照信息详细地址\",   \"affi_orgz_03\": \"[]\",   \"affi_orgz_02\": \"[{\\\"type\\\":\\\"Group\\\",\\\"code\\\":\\\"25882\\\",\\\"name\\\":\\\"公司领导\\\",\\\"attrs\\\":null}]\",   \"Interbank_number\": \"联 行 号\",   \"bank_account_num0\": \"银行账号\",   \"mailing_address\": \"邮寄地址\",   \"authorized_distribution_channels\": \"授权经销渠道\",   \"payment_type\": \"01\",   \"now_network_count\": 111,   \"billing_phone\": \"开票电话\",   \"LAST_MODIFIED_TIME\": 1696818476944,   \"receiving_phone\": \"123456788923\",   \"unloading_requirements\": \"01\",   \"title\": \"客户开户申请--周飞-测试--勿动01\",   \"payment_terms\": \"Z004\",   \"DELETED\": 0,   \"custom_property\": \"1\",   \"province_city_district2\": \"天津市,市辖区,和平区\",   \"task_breakdown_table_02\": \"{\\\"value\\\":\\\"344937561667878912\\\"}\",   \"bank_name\": \"开户行名称\",   \"task_breakdown_table_01\": \"{\\\"value\\\":\\\"344937561625935872\\\"}\",   \"company_registration_date\": 1696818145792,   \"task_breakdown_table_03\": \"{\\\"value\\\":\\\"344937561709821952\\\"}\",   \"contract_type_02\": \"低温\",   \"contract_type_03\": \"都市牧人\",   \"contract_type_01\": \"常温\",   \"office_area\": \"办公面积\",   \"FLOW_STATUS\": 1,   \"carrier\": \"1\",   \"CREATE_DEPT_NAME\": \"常温龙岗办\",   \"legal_person_name\": \"法人姓名\",   \"CREATOR_NAME\": \"饶兰凤\",   \"food_business_license_number\": \"11112334556456233\",   \"transit_area\": \"粤B-L92#\",   \"remarks\": \"备  注\",   \"province_city_district\": \"北京市,市辖区,东城区\" }";

        JsonNode jsonNode1 = JSONUtil.readNode(json1);
        JsonNode jsonNode2 = JSONUtil.readNode(json2);


        Map<String, String> vkMap = new HashMap<>();

        getVkMap(jsonNode1, vkMap);

        StringBuilder sb = new StringBuilder();
        for (String key : vkMap.keySet()) {
            sb.append("('1111', '" + key + "'),");
        }


        System.out.println(sb.toString());


    }

    private static void getVkMap2(JsonNode jsonNode, Map<String, String> vkMap) {
        Iterator<Map.Entry<String, JsonNode>> fields = jsonNode.fields();
        while (fields.hasNext()) {
            Map.Entry<String, JsonNode> next = fields.next();
            String key = next.getKey();
            JsonNode value = next.getValue();
            vkMap.put(value.asText(), key);
        }
    }

    private static void getVkMap(JsonNode jsonNode, Map<String, String> vkMap) {

        JsonNode customerInfo = jsonNode.get("customerInfo");
        Iterator<Map.Entry<String, JsonNode>> fields = customerInfo.fields();
        while (fields.hasNext()) {
            Map.Entry<String, JsonNode> next = fields.next();
            String key = next.getKey();
            JsonNode value = next.getValue();
            vkMap.put("customerInfo." + key, value.asText());
        }

        JsonNode receiveInfo = jsonNode.get("receiveInfo");
        fields = receiveInfo.fields();
        while (fields.hasNext()) {
            Map.Entry<String, JsonNode> next = fields.next();
            String key = next.getKey();
            JsonNode value = next.getValue();
            vkMap.put("receiveInfo." + key, value.textValue());
        }

        JsonNode cstomerOrg = jsonNode.get("cstomerOrg");
        fields = cstomerOrg.fields();
        while (fields.hasNext()) {
            Map.Entry<String, JsonNode> next = fields.next();
            String key = next.getKey();
            JsonNode value = next.getValue();
            vkMap.put("cstomerOrg." + key, value.asText());
        }


    }


    private static String generateSignature() {
        List<SignatureParam> signatureParams = new ArrayList<>();
        Long timestamp=System.currentTimeMillis();
        String uuid= UUIDUtil.generateUUID();
        signatureParams.add(new SignatureParam("x-qys-open-timestamp", timestamp.toString(), 3));
        signatureParams.add(new SignatureParam("x-qys-open-nonce", uuid, 4));
        signatureParams.add(new SignatureParam("x-qys-open-accesstoken", "XTzEWEcC4G", 1));
        signatureParams.add(new SignatureParam("AppSecret", "ubUFunEWPL227vI2nDDOsp77eQI2jf", 2));

        Collections.sort(signatureParams);
        String signature = SignatureUtil.generateSignature(signatureParams, new MD5Signature());
        System.out.println("timestamp:"+timestamp);
        System.out.println("uuid:"+uuid);
        System.out.println("Signature:"+signature);







        return null;
    }


    public static void main(String[] args) throws Exception {
        //给字段添加注释
//        addAnnotation();
        buildSetter();
//        buildIDs();
//        fieldMapping();
//        generateSignature();
    }

}